package com.leslie.app.controller;


import com.leslie.app.dto.ArticleDto;
import com.leslie.app.entity.Article;
import com.leslie.app.entity.Result;
import com.leslie.app.service.ArticleService;
import com.leslie.app.service.impl.ArticleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/articles")
public class ArticleController {
    @Autowired
    ArticleServiceImpl articleService;

    @GetMapping
    private Result<List<Article>> getAllArticles() {
        List<Article> articleList = articleService.getArticleList();
        return Result.success(articleList);
    }

    @PostMapping
    private Result<Article> addArticle(@RequestBody Article article) {
        articleService.add(article);
        return Result.success(article);
    }

    @GetMapping("/{id}")
    private  Result<ArticleDto> getArticleById(@PathVariable("id") Integer id) {
        ArticleDto article = articleService.getArticleById(id);
        return Result.success(article);
    }
}
